import pyaudio

p = pyaudio.PyAudio()

# 获取所有可用的音频设备信息
for i in range(p.get_device_count()):
    dev_info = p.get_device_info_by_index(i)
    print(f"Device {i}: {dev_info['name']}")
    print(f"  Max Input Channels: {dev_info['maxInputChannels']}")
    print(f"  Default Sample Rate: {dev_info['defaultSampleRate']}")
    print(f"  Supported Sample Rates: {p.get_device_info_by_index(i).get('defaultSampleRate')}")

# 特别查看默认输入设备
try:
    default_input = p.get_default_input_device_info()
    print(f"\nDefault Input Device: {default_input['name']}")
    print(f"Default Sample Rate: {default_input['defaultSampleRate']}")
except Exception as e:
    print(f"Error getting default input device: {e}")

p.terminate()